home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / WASTE 1.2 / WASTE Demo ƒ / WEDemoAbout.c < prev    next >
Text File  |  1996-05-19  |  3KB  |  138 lines

  1. /*
  2.     WASTE Demo Project:
  3.     About Boxes
  4.  
  5.     Copyright © 1993-1996 Marco Piovanelli
  6.     All Rights Reserved
  7.  
  8.     C port by John C. Daub
  9. */
  10.  
  11.  
  12. #ifndef __WEDEMOAPP__
  13. #include "WEDemoIntf.h"
  14. #endif
  15.  
  16. // some local stuff
  17.  
  18. enum {
  19.     kItemTextPane    =    3
  20. };
  21.  
  22. OSErr WETextBox( short textResID, const Rect *bounds, WEAlignment alignment )
  23. {
  24.     WEReference        we = nil;
  25.     Handle            hText = nil;
  26.     Handle            hStyles = nil;
  27.     LongRect        longBounds;
  28.     SInt8            saveTextState, saveStylesState;
  29.     OSErr            err;
  30.  
  31.     // create a new WE instance
  32.  
  33.     WERectToLongRect( bounds, &longBounds );
  34.     if ( ( err = WENew( &longBounds, &longBounds, 0, &we ) ) != noErr )
  35.         goto cleanup;
  36.  
  37.     // set the alignment style
  38.  
  39.     WESetAlignment( alignment, we );
  40.  
  41.     // load the styl resource and make it unpurgeable
  42.  
  43.     hStyles = GetResource( kTypeStyles, textResID );
  44.     if ( ( err = ResError( ) ) != noErr )
  45.         goto cleanup;
  46.     saveStylesState = HGetState( hStyles );
  47.     HNoPurge( hStyles );
  48.  
  49.     // load the text resource and lock it
  50.  
  51.     hText = GetResource( kTypeText, textResID );
  52.     if ( ( err = ResError( ) ) != noErr )
  53.         goto cleanup;
  54.     saveTextState = HGetState( hText );
  55.     HLockHi( hText );
  56.  
  57.     // insert the text
  58.  
  59.     if ( ( err = WEInsert( *hText, GetHandleSize( hText ), (StScrpHandle) hStyles, nil, we ) ) != noErr )
  60.         goto cleanup;
  61.  
  62.     // clear the result code
  63.  
  64.     err = noErr;
  65.  
  66. cleanup:
  67.  
  68.     if ( hText != nil )
  69.     {
  70.         HSetState( hText, saveTextState );
  71.     }
  72.  
  73.     if ( hStyles != nil )
  74.     {
  75.         HSetState( hStyles, saveStylesState );
  76.     }
  77.  
  78.     WEDispose( we );    // WEDispose is nil-safe
  79.  
  80.     // return the result code
  81.  
  82.     return err;
  83. }
  84.  
  85. static pascal void DrawUserItem( DialogRef dialog, short item )
  86. {
  87.     Rect r;
  88.  
  89.     // draw the text, centered, in the item rect
  90.  
  91.     GetDialogItemRect( dialog, item, &r );
  92.     WETextBox( GetWRefCon( GetDialogWindow( dialog ) ), &r, weCenter );
  93. }
  94.  
  95. void DoAboutBox( short dialogID )
  96. {
  97.     DialogRef aboutBox;
  98.     short itemHit;
  99.  
  100. #ifdef __cplusplus
  101.     static UserItemUPP sBoxPainterUPP = NewUserItemProc( DrawUserItem );
  102. #else
  103.     static UserItemUPP sBoxPainterUPP = nil;
  104.     if ( sBoxPainterUPP == nil )
  105.     {
  106.         sBoxPainterUPP = NewUserItemProc( DrawUserItem );
  107.     }
  108. #endif
  109.  
  110.     // get the about box
  111.  
  112.     if ( ( aboutBox = GetNewDialog( dialogID, nil, (WindowRef) -1L ) ) == nil )
  113.         return;
  114.  
  115.     // install a user item drawing procedure for the text pane
  116.  
  117.     SetDialogItemProc( aboutBox, kItemTextPane, sBoxPainterUPP );
  118.  
  119.     // store ID of TEXT/styl pair (= ID of dialog template) in dialog refCon
  120.  
  121.     SetWRefCon( GetDialogWindow( aboutBox ), dialogID );
  122.  
  123.     // put up the dialog
  124.  
  125.     SetCursor( &qd.arrow );
  126.  
  127.     ShowWindow( GetDialogWindow( aboutBox ) );
  128.     SetGrafPortOfDialog( aboutBox );
  129.  
  130.     // wait for a click
  131.  
  132.     ModalDialog( GetMyStandardDialogFilter( ), &itemHit );
  133.  
  134.     // bring down the dialog
  135.  
  136.     DisposeDialog( aboutBox );
  137. }
  138.